/* Class PathNode
 * 
 * 
 */
package disasterGameProj;

public class PathNode 
{
	public PathNode myParentNode = null;
	public Tile myTile = null;
	public int g_Score = 0;// shortest distance from start node 
	public int h_Score = 0;// estimated distance to end node (Manhattan)
	public int f_Score = 0;// g_Score + h_Score
	
	public PathNode(Tile tile) 
	{
		myTile = tile;
	}
	
	public PathNode( )
	{}

	public void createMapHeuristics( PathNode parentNode, Tile endPos )
	{
		int xTilesAway = ABS( endPos.xLoc, myTile.xLoc );
		int yTilesAway = ABS( endPos.yLoc, myTile.yLoc );
			
		g_Score = parentNode.g_Score + 1;

		h_Score = xTilesAway + yTilesAway;
		
		if( myTile.myName.equals( "R" ) )
			f_Score = ( 3 * g_Score + h_Score ) - 1;
		else
			f_Score = ( 3 * g_Score ) + h_Score;
		
	}
	
	// for aStarAlgorithm
	public void calculateHeuristics( PathNode parentNode, Tile endPos )
	{
		int xTilesAway = ABS( endPos.xLoc, myTile.xLoc );
		int yTilesAway = ABS( endPos.yLoc, myTile.yLoc );
			
		g_Score = parentNode.g_Score + 1;

		h_Score = xTilesAway + yTilesAway;
		
		f_Score = g_Score + h_Score;
		
	}

	private int ABS(int a, int b) 
	{
		if( ( a - b ) > 0 )
			return ( a - b);
		else
			return ( (a - b) * -1 );
	}

	
	
}